<%@page import="cn.lily.com.enviroment.Enviroment"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="cn.lily.inst.web.frames.FrameConfig" %>
<%@ page import="cn.lily.web.util.context.WebContext" %>
<%@ page import="cn.lily.esb.context.AuthEntity" %>
<%@ page import="cn.lily.com.container.ram.ApplicationContext"%>
<%@ page import="app.portal.util.UtilMethod"%>
<%@ page import="cn.lily.com.db.sql.DBManager"%>
<%@ page import="app.portal.dao.Pt_app_infoBean"%>
<%@ page import="app.portal.dao.Pw_app_menu_infoBean"%>
<%@ page import="app.portal.util.EnumValue"%>
<%@ page import="cn.lily.com.db.DBFactory"%>
<%@ page import="cn.lily.com.db.container.reader.DataTable"%>
<%@ page import="cn.lily.com.configure.util.ESBSetting"%>
<%@ page import="net.sf.json.JSONArray" %>
<%@ include file="/frames/logbegin.jsp" %>
<%
  String skinName = "";
  String contextPath = ""; 
  AuthEntity authEntity = (AuthEntity) session.getAttribute(WebContext.LOG_AUTH_CONTEXT);
  if (authEntity != null) { 
  	skinName = authEntity.getSkinName();
  	contextPath = authEntity.getContextPath();
  }else{
	System.out.println("用户信息已经丢失。。。。。。。。。。。。。。。。。。");
  }
		  
  FrameConfig.setContextPath(contextPath);
  String appid=request.getParameter("appid");
  authEntity.getOperEntity().setAppID(appid);
  ApplicationContext.setAuthEntity(request.getSession().getId(), authEntity);
  
  DBManager dbManager=DBFactory.getActionDB();
  DataTable appTable=dbManager.executeQueryTable("select app_nam,sign_ico from ${schema}.pw_app_detail where pw_app_id='"+appid+"'");
  String appname="";
  String signico="";
  while(appTable.next()){
	  appname=appTable.getString("app_nam");
	  signico=appTable.getString("sign_ico");
	  if(signico==null || "".equals(signico.trim())){
		  signico=FrameConfig.getSkinImg("appappfile/default.png");
      }
  }
  System.out.println(signico);
  //设置应用编号
  String baseSql="";
  if(EnumValue.OPER_TYP_1.equals(authEntity.getOperEntity().getOperType())) {
	  baseSql=" select * from ${schema}.PW_APP_MODEL where pw_app_id='"+appid+"' order by view_idx ";
  }else{
	  baseSql=" select * from ${schema}.PW_APP_MODEL where pw_app_id='"+appid+"' and MODE_ID in ( select a.MODE_ID from ${schema}.PW_ROLE_RES a ,PW_OPER_ROLE b where a.ROLE_ID=b.ROLE_ID and b.oper_key='"+authEntity.getOperatorId()+"') order by view_idx ";
  }
  DataTable menuTable=dbManager.executeQueryTable(baseSql);
  JSONArray jarrModId = new JSONArray();
  JSONArray jarrModNam = new JSONArray();
  JSONArray jarrMenuId = new JSONArray();
  JSONArray jarrMenuNam = new JSONArray();
  JSONArray jarrMenuSrc = new JSONArray();
  JSONArray jarrAppId = new JSONArray();
  int i=0;int j=0;
  while(menuTable.next()){
	  jarrModId.add(i,menuTable.getString("mode_id"));
	  jarrModNam.add(i,menuTable.getString("mode_nam"));
	  i++;
      String itemsql="";
      if(EnumValue.OPER_TYP_1.equals(authEntity.getOperEntity().getOperType())) {
          itemsql=" SELECT a.MENU_ID,a.APP_ID,a.MENU_NAM,b.menu_src FROM ${schema}.PW_APP_MENU a,${schema}.PW_APP_MENU_INFO b "
          	  +" WHERE a.MENU_ID=b.MENU_ID and a.MODE_ID='"+menuTable.getString("mode_id")+"' order by a.view_idx ";
      }else{
          itemsql="SELECT a.MENU_ID,a.APP_ID,a.MENU_NAM,b.menu_src FROM ${schema}.PW_ROLE_RES a,${schema}.PW_APP_MENU_INFO b,${schema}.PW_OPER_ROLE c,${schema}.pw_role d "
        	  +" WHERE a.MENU_ID=b.MENU_ID and a.role_id=c.role_id and c.role_id=d.role_id and d.status='1' and c.oper_key='"+authEntity.getOperatorId()+"' and a.MODE_ID='"+menuTable.getString("mode_id")+"' order by a.view_idx ";
	  }
      DataTable itemTable = DBFactory.getActionDB().executeQueryTable(itemsql);
	  if(itemTable.getRecordCount()>0){
    	  while(itemTable.next()){
    		  jarrMenuId.add(j,menuTable.getString("mode_id")+"&"+itemTable.getString("menu_id"));
    		  jarrMenuNam.add(j,itemTable.getString("menu_nam"));
    		  //jarrMenuSrc.add(j,itemTable.getString("menu_src"));
    		  jarrAppId.add(j,itemTable.getString("app_id"));
    		  j++;
          }
      }
  }
  dbManager.free();
  
%>
<%@ include file="/frames/logend.jsp" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta charset=utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%=FrameConfig.getAppName()%></title>
	<link href="/<%=ESBSetting.getString("appCode")%>/public/style/skin_bootstrap/bootstrap-3.3.0/bootstrap.css" rel="stylesheet" media="screen">
	<link href="/<%=ESBSetting.getString("appCode")%>/public/font/awesome/font-awesome-4.7.0.css" rel="stylesheet">
  	<link href="<%=FrameConfig.getCSSPath("appindex.css") %>" rel="stylesheet" />
</head>
<body>
  <div id="app" appid=<%=appid %> signico=<%=signico%> contextPath=<%=contextPath%> sessionID=<%=session.getId()%> style="display:none;"></div>
  <div id="app-tab" style="height:100%;margin:0 auto;padding:0px;">
	    <div class="tabbable" style="margin:0px;padding:0px;height:31px;">
	        <ul id="app-tab-menu" class="nav nav-tabs">
	          <li id="app-menu-index" class="active"><a href="#app-condent-index" data-toggle="tab">流程引导</a></li>
	          <li id="app-dropdown-li">           
	            <ul id="app-dropdown-menu" class="drop-menu">
	              <li style="border-bottom:1px solid #ccc"><a tabid="app-menu-index" contentid="app-condent-index" onclick="changeTabFocus(this)" href="#app-condent-index" data-toggle="tab" tabid="tab-index">流程引导</a>
	              </li>
	            </ul>
	          </li>
	        </ul>
	  </div>
	  <div id="app-tab-content" class="tab-content" style="height:100%;">
	    <div class="tab-pane active" id="app-condent-index" style="height:100%;">
	      <iframe src="flowMain.jsp" width="100%" frameborder="0" scrolling="no" height="97%" ></iframe>
	    </div>
	  </div>
  </div>
  <script src="<%=FrameConfig.getBaseJsUrl() %>/common/jquery-1.9.1.min.js"></script>
  <script src="/<%=ESBSetting.getString("appCode")%>/public/js/skin_bootstrap/bootstrap-3.3.0/bootstrap-3.3.0.js"></script>
  <script src="<%=FrameConfig.getJsUrl("appindex.js")%>"></script>
  <script type="text/javascript">
  $(function(){
		var modId=<%=jarrModId %>;
		var modNam=<%=jarrModNam %>;
		var menuId=<%=jarrMenuId %>;
		var menuNam=<%=jarrMenuNam %>;
		//var menuSrc=<%=jarrMenuSrc %>;
		var appID=<%=jarrAppId %>;
		// 获取应用信息
		var appid = $("#app").attr("appid");
		var signico=$("#app").attr("signico");
		var contextPath=$("#app").attr("contextPath");
		var sessionID=$("#app").attr("sessionID");
		var btnMenu="";
		
		//动态生成菜单
		if(modId.length>0){	
			for (var i=0;i<modId.length;i++){
				btnMenu=btnMenu+"<dt onmouseover=\"showUl(this)\" onmouseout=\"hideUl(this)\">"+modNam[i]+"<ul id=\"btnMenu\" style=\"display:none\">";
				for (var j=0;j<menuId.length;j++){
					if(menuId[j].split("&")[0]==modId[i]){
						btnMenu=btnMenu+"<li onclick=\"opentab(this)\" contextPath=\""+contextPath+"\" appID=\""+appID[j]+"\" pw_appid=\""+appid+"\" sessionID=\""+sessionID+"\" menuid=\""+menuId[j].split("&")[1]+"\" menunam=\""+menuNam[j]+"\" >"+menuNam[j]+"</li>";
					}
				}
				btnMenu=btnMenu+"</ul>"+"</dt>";
			}
		}
		btnMenu="<img src=\""+signico+"\" width=\"10\" /><p appid=\""+appid+"\" onclick=\"closeAppTab(this)\"></p><dl style=\"display:none\">"+btnMenu+"</dl><div class=\"effect\"></div>";
		// 获取父级页面元素
		var tabid = "tab-" + appid;
		var new_tab = $("#" + tabid +" a", parent.document);
		if (new_tab.length != 0) {	
			$("#tab-menu", parent.document).find(".effect").each(function(){
				$(this).remove();
			});
			new_tab.append(btnMenu);
		}  
		//点击空白收回下拉菜单
		$("html,body").click(function(e){
			  if(e.target.id.indexOf("app-dropdown-li")==-1){
			      $(".drop-menu").hide();
			  } 
		});
		$("#app-dropdown-li").click(function(){
		    $(".drop-menu").show();
		});
	})

  </script>
</body>
</html>
